<?php
include 'score_lib.php';

$a_css_files = array (
    array ( 'path' => 'plugins/bootstrap-modal/css/bootstrap-modal.css' ),
);

$a_js_files = array (
    array ( 'path' => 'plugins/jquery-file-upload/js/vendor/tmpl.min.js' ),
    array ( 'path' => 'plugins/bootstrap-modal/js/bootstrap-modal.js' ),
    array ( 'path' => 'plugins/bootstrap-modal/js/bootstrap-modalmanager.js' ),
    array ( 'path' => 'scripts/nh-score.js' ),
);

$a_js_class[] = 'NH_Score.init();';

// <editor-fold defaultstate="collapsed" desc="Get Data">
$a_User = $a_User_Score = array ();
$s_Where = $v_startdate = $v_enddate = '';
$a_Hidden_Columns = array(0 => current(array_keys($a_Dot_KiemTra)));

// <editor-fold defaultstate="collapsed" desc="Make Where">
if ($s_category_team) {
    
    $db_query = "
        select  userid
        from    user_class
        where   course = '" . $a_KhoaHoc_Info['start_year'] . "' and team = '$s_category_team' and level = '$s_category_level' and crew = '$s_category_crew' ";
    
    $db_result = db_query($db_conn, $db_query);

    while ($d_row = db_fetch($db_result)) {
        $a_User[$d_row->userid] = $d_row->userid;
    }
    
    $s_Where = $s_Where  . ' and userid in ("' . implode('", "', $a_User) . '")';
}

make_where($s_Where, $a_filterings);
// </editor-fold>

if (!empty($a_User)) {

    $db_query  = db_get_query($a_tablecolumns_namhoa_user) . $s_Where . " and $s_get_THIEU_NHI_condition " . ' order by firstname';
    $db_result = db_query($db_conn, $db_query);

    $a_User = array ();
    
    while ($d_row = db_fetch($db_result)) {
        $a_User[$d_row->userid] = $d_row;
    }
    
    if (!empty($a_User)) {
    
        $db_query = "
            select  userid, scoretype, data, score
            from    user_score
            where   userid  in ('" . implode("', '", array_keys($a_User)) . "') and
                    type = 'HOC_LUC'
            order by scoretype";

        $db_result = db_query($db_conn, $db_query);

        while ($d_row = db_fetch($db_result)) {
            $a_User_Score[$d_row->userid][$d_row->data][$d_row->scoretype] = $d_row->score;
            $a_Hidden_Columns[0] = $d_row->scoretype; // Only Show the last scoretype on Mobile UI
        }
    }
}

if (!empty($a_Hidden_Columns)) {
    foreach ($a_tmp = array_keys($a_Dot_KiemTra) as $key ) {

        if ($key == $a_Hidden_Columns[0]) {
            $a_Hidden_Columns[1] = current($a_tmp);
        }
    }
}
$a_permission = get_passport_action_from_module($db_conn, array('DIEM_KIEM_TRA'));
// </editor-fold>

include 'lib_head.php';
?>
<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<div id="portlet-config" class="modal hide">
    <div class="modal-header">
        <button data-dismiss="modal" class="close" type="button"></button>
        <h3>Bộ Lọc</h3>
    </div>
    <div class="modal-body">
        Điền thông tin cần thiết để lọc được dữ liệu thích hợp.
    </div>
</div>
<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<div class="row-fluid">
    <!-- BEGIN BORDERED TABLE PORTLET-->
    <div class="portlet box green">
        <div class="portlet-title">
            <div class="caption"><i class="icon-filter"></i>Lọc Dữ Liệu - Khóa <?=$a_KhoaHoc_Info['name']?></div>
            <div class="tools">
                <a href="javascript:;" class="collapse"></a>
                <a href="#portlet-config" data-toggle="modal" class="config"></a>
            </div>
        </div>
        <div class="portlet-body">
            <form action="" style="margin: 0">
                <div class="pull-left margin-right-20">
                    <div class="control-group">
                        <label class="control-label" >Ngành</label>
                        <div class="controls">
                            <select name="category_team" class="m-wrap span12">
                                <option value=""></option>
                                <?php foreach ($a_Nganh as $v_key => $v_value) { ?>
                                    <option <?= $s_category_team == $v_key ? 'selected="selected"' : '' ?> value="<?= $v_key ?>"><?= $v_value ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="pull-left margin-right-20">
                    <div class="control-group">
                        <label class="control-label" >Cấp</label>
                        <div class="controls">
                            <select name="category_level" class="m-wrap span12">
                                <option value=""></option>
                                <?php foreach ($a_Cap as $v_key => $v_value) { ?>
                                    <option <?= $s_category_level == $v_key ? 'selected="selected"' : '' ?> value="<?= $v_key ?>"><?= $v_value ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="pull-left margin-right-20">
                    <div class="control-group">
                        <label class="control-label" >Đội</label>
                        <div class="controls">
                            <select name="category_crew" class="m-wrap span12">
                                <option value=""></option>
                                <?php foreach ($a_Doi as $v_key => $v_value) { ?>
                                    <option <?= $s_category_crew == $v_key ? 'selected="selected"' : '' ?> value="<?= $v_key ?>"><?= $v_value ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="pull-left">
                    <div class="control-group">
                        <label class="control-label">&ensp;</label>
                        <div class="controls">
                            <div class="input-prepend">
                                <button class="btn blue">BẮT ĐẦU LỌC <i class="m-icon-swapright m-icon-white"></i></button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </form>
        </div>
    </div>
    <!-- END BORDERED TABLE PORTLET-->
    <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th rowspan="2" style="vertical-align: middle">Họ và Tên</th>
                <?php foreach ($a_Dot_KiemTra as $v_scoretype_key => $v_scoretype_value) { ?>
                <th style="text-align: center" class="<?=!in_array($v_scoretype_key, $a_Hidden_Columns) ? 'hidden-phone' : ''?>" colspan="<?= count($a_SoLan_KiemTra) ?>"><?= $v_scoretype_value ?></th>
                <?php } ?>
            </tr>
            <tr>
                <?php foreach ($a_Dot_KiemTra as $v_scoretype_key => $v_scoretype_value) {
                    foreach ($a_SoLan_KiemTra as $v_key => $v_value) { ?>
                <th class="<?=!in_array($v_scoretype_key, $a_Hidden_Columns) ? 'hidden-phone' : ''?>" style="text-align: center"><?= $v_value ?></th>
                <?php } } ?>
            </tr>
        </thead>
        <?php foreach ($a_User as $v_counter => $d_user) : ?>
        <tbody>
            <tr>
                <td><span class="hidden-phone"><?=$d_user->saint?></span> <?=$d_user->username?></td>
                <?php foreach ($a_Dot_KiemTra as $v_scoretype_key => $v_scoretype_value) {
                    foreach ($a_SoLan_KiemTra as $v_key => $v_value) { 
                        $v_tmp_value  = @$a_User_Score[$d_user->userid][$v_key][$v_scoretype_key] ?>
                <td class="<?=!empty($a_permission) ? 'hocluc' : '' ?> <?=!in_array($v_scoretype_key, $a_Hidden_Columns) ? 'hidden-phone' : ''?>" scoretype="<?=$v_scoretype_key?>" score="<?=$v_tmp_value?>" data="<?=$v_key?>" userid="<?=$d_user->userid?>" username="<?=$d_user->username?>" style="text-align: center;"><?=$v_tmp_value?></td>
                <?php } } ?>
            </tr>
        </tbody>
        <?php endforeach; ?>
    </table>
</div>
<div id="responsive" class="modal hide fade" tabindex="-1"></div>
<?php include 'lib_tail.php'; ?>